<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin Model
 */
class Banner extends Model
{

    public static array $type_name = [
        1=> '首页轮播图',
        2=> '首页中部图',
    ];

    public static array $px_text = [
        1=> '702px * 340px',
        2=> '344px * 344px',
    ];

    public function getList($type) {
        if (!$type) {
            return [];
        }
        $list = $this->where(['status'=>1,'delete_time'=>0])->whereIn('type', $type)
            ->field('title,type,image,url')
            ->order('sort desc,id asc')
            ->select()->toArray();
        foreach ($list as &$val) {
            $val['type_name'] = self::$type_name[$val['type']] ?? '';
            $val['image'] = get_image_url($val['image']);
        }
        return $list;
    }
}
